class Solution {
public:
    vector<int> sortArrayByParityII(vector<int>& nums) {
        int i = 0;
        int j = 0;
        int len = nums.size();
        while(i < len && j < len){
            swap(nums[i],nums[j]);
            while(i < len && !(i % 2 == 0 && nums[i] % 2 == 1)){
                i++;
            }
            while(j < len && !(j % 2 == 1 && nums[j] % 2 == 0)){
                j++;
            }
        }
        return nums;
    }
};
